"use client";
import useSWR from "swr";

const fetcher = async () => {
  return fetch("/user.json").then((res) => res.json());
};

export default function Page() {
  const { data, error, isLoading } = useSWR("/api/user", fetcher, {
    // revalidateOnFocus: false, // 禁用窗口聚焦时自动刷新
    refreshInterval: 2000,
  });

  if (error) return <div>错误提示</div>;
  if (isLoading) return <div>加载动画...</div>;
  return <div>{data.name}</div>;
}
